﻿@{
    ViewBag.Title = "PostRpc Tests";
}

<h2>PostRpc Tests</h2>

<div>
<a href='javascript:;' onclick='testAdd(3,4);'>Test Add 3 + 4</a>
</div>

<div>
<a href='javascript:;' onclick='testExceptionThrownOnServer();'>Test Exception Thrown On Server</a>
</div>

<div>
<a href='javascript:;' onclick='testPermissionDenied();'>Test Permission Denied</a>
</div>

<div>
<a href='javascript:;' onclick='testPostRpcActionWhichDoesNotExist();'>Test PostRpc Action Which Does Not Exist</a>
</div>

<div>
<a href='javascript:;' onclick='testModelBinding();'>Test Model Binding (expect "Hello World - 2" as response description)</a>
</div>


<script type="text/javascript">//<!--

    function testAdd(x, y) {
        FlowBasis.Rpc.invokeAndWait(
            "~/Developers/PostRpcTest/TestAdd",
            { x: x, y: y },
            function (response, success) {
                if (success) {
                    alert(response.result);
                }
            });                 
    }

    function testExceptionThrownOnServer() {
        FlowBasis.Rpc.invokeAndWait(
            "~/Developers/PostRpcTest/TestThrowException",
            { message: "This should be the error message." },
            function (response, success) {
                if (success) {
                    alert("This should not have succeeded.");
                }
            }); 
    }

    function testPermissionDenied() {
        FlowBasis.Rpc.invokeAndWait(
            "~/Developers/PostRpcTest/TestPermissionDenied",
            { message: "This should be the error message." },
            function (response, success) {
                if (success) {
                    alert("This should not have succeeded.");
                }
            }); 
    }

    function testPostRpcActionWhichDoesNotExist() {
        FlowBasis.Rpc.invokeAndWait(
            "~/Developers/PostRpcTest/ThisActionShouldNotExistSoWeCanSeeErrorPageInIFrame",
            { message: "This should be the error message." },
            function (response, success) {
                if (success) {
                    alert("This should not have succeeded.");
                }
            });
        }

    function testModelBinding() {
        FlowBasis.Rpc.invokeAndWait(
            "~/Developers/PostRpcTest/TestModelBinding",
            { testModel: { someValue: "Hello World", testEnum: "Two" } },
            function (response, success) {
                if (success) {
                    alert("Response description was: " + response.result.description);
                }
            });
    }

//--></script>